#ifndef DUAL_CHESSBOARD_H
#define DUAL_CHESSBOARD_H 1

#include <vector>
#include "cvxImage.h"
#include "marker.hpp"

using std::vector;

//find two same size chessboard in one image

class DualChessboard
{
public:
	DualChessboard(const CvSize &size);
	~DualChessboard();

	bool findCorners(const Mat &image, bool isTracking, vector<Point2f> &firstCorners, 
					 vector<Point2f> &secondCorners, int distortionThreshold = 5);
	vector<Point2f> boardCorners() {return m_boardCorners;}

private:
	CvSize m_patternSize;				  //chessboard size
	vector<Point2f> m_boardCorners;     //physical position of corners in 2d
	vector<Point2f> m_markerCenters;    //physical position of marker centers

	//two chessboard, first or second
	vector<CvxMarker> m_firstPreMarkers;     //previous frame marker position
	vector<CvxMarker> m_firstCurMarkers;     //current frame marker position
	vector<CvxMarker> m_secondPreMarkers;     //previous frame marker position
	vector<CvxMarker> m_secondCurMarkers;     //current frame marker position

	//calculate corner positions in the image from homography mapping
	bool calcCornersFromMakerCenters(const vector<CvxMarker> & markers, vector<Point2f> &corners, int w, int h, int distortionThreshold, const Mat &grayImage);

};



#endif
